package com.yy.controller;

import com.yy.common.annotation.Log;
import com.yy.common.core.controller.BaseController;
import com.yy.common.core.domain.AjaxResult;
import com.yy.common.core.page.TableDataInfo;
import com.yy.common.enums.BusinessType;
import com.yy.common.utils.poi.ExcelUtil;
import com.yy.domain.ParkCar;
import com.yy.service.IParkCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 场内车辆Controller
 *
 * @author yy
 * @date 2023-03-09
 */
@RestController
@RequestMapping("/park/car")
public class ParkCarController extends BaseController
{
    @Autowired
    private IParkCarService parkCarService;

    /**
     * 查询场内车辆列表
     */
    @PreAuthorize("@ss.hasPermi('park:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkCar parkCar)
    {
        startPage();
        List<ParkCar> list = parkCarService.selectParkCarList(parkCar);
        return getDataTable(list);
    }

    /**
     * 导出场内车辆列表
     */
    @PreAuthorize("@ss.hasPermi('park:car:export')")
    @Log(title = "场内车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkCar parkCar)
    {
        List<ParkCar> list = parkCarService.selectParkCarList(parkCar);
        ExcelUtil<ParkCar> util = new ExcelUtil<ParkCar>(ParkCar.class);
        util.exportExcel(response, list, "场内车辆数据");
    }

    /**
     * 获取场内车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('park:car:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(parkCarService.selectParkCarById(id));
    }

    /**
     * 新增场内车辆
     */
    @PreAuthorize("@ss.hasPermi('park:car:add')")
    @Log(title = "场内车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkCar parkCar)
    {
        return toAjax(parkCarService.insertParkCar(parkCar));
    }

    /**
     * 修改场内车辆
     */
    @PreAuthorize("@ss.hasPermi('park:car:edit')")
    @Log(title = "场内车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkCar parkCar)
    {
        return toAjax(parkCarService.updateParkCar(parkCar));
    }

    /**
     * 删除场内车辆
     */
    @PreAuthorize("@ss.hasPermi('park:car:remove')")
    @Log(title = "场内车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkCarService.deleteParkCarByIds(ids));
    }
}
